﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class CollegeBLL
    {
        public static IQueryable<CollegeInfo> GetList()
        {
            using (var dal = new CollegeDAL(Settings.ConnectionName))
            {
                var re = dal.SelectQueryable(o => true);
                return re;
            }
        }

        public static CollegeInfo Get(int id)
        {
            using (var dal = new CollegeDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.Id == id);
                return re;
            }
        }

        public static List<CollegeInfo> GetAll()
        {
            using (var dal = new CollegeDAL(Settings.ConnectionName))
            {
                var re = dal.Select(o => true);
                return re;
            }
        }

        public static bool IsExist(Expression<Func<CollegeInfo, bool>> expression)
        {
            using (var dal = new CollegeDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(expression) != null;
            }
        }

        public static bool Edit(CollegeInfo info)
        {
            using (var dal = new CollegeDAL(Settings.ConnectionName))
            {
                return dal.Update(info) != null;
            }
        }

        public static bool Add(CollegeInfo info)
        {
            using (var dal = new CollegeDAL(Settings.ConnectionName))
            {
                return dal.Add(info) != null;
            }
        }
    }
}
